package com.aifund.common.util;

import com.aifund.common.service.SystemConfigService;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

@Component
public class JwtUtil {

    @Autowired
    SystemConfigService systemConfigService;

    public Long getUserId(HttpServletRequest request){
        final String headerToken=request.getHeader("token");
        Claims claims = Jwts.parser().setSigningKey(systemConfigService.getJwtSecret()).parseClaimsJws(headerToken).getBody();
        String tokenUserId=(String)claims.get("userId");
        return Long.parseLong(tokenUserId);
    }



}
